#include <linux/types.h> /* u_int16_t */
#include "rtapi/rtapi_math.h"

// int stderr;

// int fputs(const char* str) { return 0; }

// unsigned int fwrite(const void* ptr, unsigned int size, unsigned int nobj, void* stream) { return nobj; }

// static int errno;

// int* __errno_location(void) { return &errno; }

// void __assert_fail(const char* s, const char* file, unsigned int line, const char* function) { return; }

#ifndef isnan
int isnan(double x)
{
    /* Return zero if x is a real number. */
    int a;
    /* According to notes, a floating point number consists of 8 bytes.
       Expressed as a 64 bit No. the sign will be B63. If bits 52-62 equal
       0x7FF and bits 0-61 are non-zero, the number is a NaN. If bits 52-62
       equal 0x7FF and bits 0-61 are zero, the number is infinite. An infinite
       number will still cause errors so it should be safe to flag it as a
       NaN. */
    u_int16_t* c = (u_int16_t*)&x;
    a = c[3] & 0x7FF0;
    return (a == 0x7FF0);
}
#endif

#ifndef __isnan
int __isnan(double x)
{ /* There must be a better way of doing this ! 
				 */
    int a;
    u_int16_t* c = (u_int16_t*)&x;
    a = c[3] & 0x7FF0;
    return (a == 0x7FF0);
}
#endif

// int RTdummy(void) { return stderr; }
